package com.server.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;
import com.server.common.AESUtils;
import com.server.entity.Result;
import com.server.entity.Result_content;

@Controller
@RequestMapping("/api")
public class AppController {

	@RequestMapping("/login")
	public String start(HttpSession session) {
		String url = "http://10.1.13.104:8078/didi-car/RequestReportsService";
		JSONObject postData = new JSONObject();
		postData.put("content",
				"lUBQ0vNqdCRVe6H3XuIP4xBJJLlSEuDdvU/xbrqOcBynozallFJ0kvnjv81iQdOX8QlkmBPiRie2ZLO+Sli+PSCxAA+hruU0+bs5pXzXFVe+88WAePWD3HkwkdD8LwfZh/9KSJLCS0DPma9kWQBOGwBJ/dMpKK7vYky3A4RmgxubMVehU5Y/hvbpcVV10h6NAmVQ5gn1Cox3uGGVDmJvjulPg5dHa0HATo6xjUhpyoC7xelKxkUxGCYBI2JMVOqvbOC3YBcB6rlUiRuMJesrk8PusAfdKmB9QcFG5+nfouNuCrA/QUhqaNMy3igI4u2qlrswrqvwv4gYJSbKuaStRGAiubEnVMkPuWrWke9IZNNysjKZ8Yu4NH1IGhNa37SruB57MRu1ugW9t9OJs5yiz0IP+r46W/HSFpzzK6Qar9NxOgylaAsnq04KXdCSJeSKF3cMRuJwEtx/0UvA1Mp0RWAZnljvPfVX5OI4Qr3Il+IY7e+XfvkzVxLRN/WQh/JZ");
		postData.put("inscompanyId", 1);

		RestTemplate client = new RestTemplate();
		JSONObject json = client.postForEntity(url, postData, JSONObject.class).getBody();
		Result result = json.toJavaObject(Result.class);

		JSONObject content_json = JSONObject.parseObject(AESUtils.decryptBase64("123456", result.getContent()));
		Result_content content = JSONObject.toJavaObject(content_json, Result_content.class);
		session.setAttribute("resultCode", content.getResponseHead().getAppCode());
		session.setAttribute("resultMessage", content.getResponseHead().getAppMessage());
		return "result";
	}
	
	@RequestMapping("/bootstrap")
	public String o_bootstrap() {
		return "bootstrap";
	}
	

}
